package sk.gtug.pivoplus.malepivo.widget;

import sk.gtug.pivoplus.malepivo.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.widget.ImageView;

public class CompassView extends ImageView {

	private int mDirection = 0;

	public CompassView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setImageResource(R.drawable.compass_arrow);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		Matrix matrix = canvas.getMatrix();
		canvas.rotate(mDirection, getWidth() * 0.5f, getHeight() * 0.5f);
		super.onDraw(canvas);
		canvas.setMatrix(matrix);
	}

	public void setDirection(int direction) {
		mDirection = direction;
		invalidate();
	}

	public int getDirection() {
		return mDirection;
	}
}
